function addZero(num) {
    return num < 10 ? "0" + num : num;
  }
  export default {
    addZero: function(num) {
      return num < 10 ? "0" + num : num;
    },
    formatDateTime: function(date) {
      const time = new Date(Date.parse(date));
      time.setTime(time.setHours(time.getHours()));
      const Y = time.getFullYear() + ".";
      const M = this.addZero(time.getMonth() + 1) + ".";
      const D = this.addZero(time.getDate()) + " ";
      const h = this.addZero(time.getHours()) + ":";
      const m = this.addZero(time.getMinutes()) + ":";
      const s = this.addZero(time.getSeconds());
      return Y + M + D + h + m + s;
    },
    formatDateTime2: function(date) {
      const time = new Date(Date.parse(date));
      time.setTime(time.setHours(time.getHours()));
      const Y = time.getFullYear();
      const M = time.getMonth() + 1;
  
      return Y + "年" + M + "月";
    },
    formatDateTime3: function(date) {
      const time = new Date(Date.parse(date));
      time.setTime(time.setHours(time.getHours()));
      const Y = time.getFullYear();
      const M = time.getMonth() + 1;
      const D = this.addZero(time.getDate()) + " ";
      return Y + "年" + M + "月" + D + "日";
    },
    formatDateTime4:function(str){
        var date = new Date(str );//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() 
    var  M = date.getMonth()+1
    var  D = date.getDate()
    var H = date.getHours() 
    var MIN = date.getMinutes()
    var s = date.getSeconds();

    Y = Y < 10 ? ('0' + Y) : Y
    M = M < 10 ? ('0' + M) : M
    H = H < 10 ? ('0' + H) : H
    MIN = MIN < 10 ? ('0' + MIN) : MIN
    s = s < 10 ? ('0' + s) : s
    D = D < 10 ? ('0' + D) : D
    var time = Y + '-' + M + '-' + D +' ' + H+ ':' + MIN + ':' + s 
    return time
      },
      formatDateTime5:function(str) {
        var date = new Date(str );
        var Y = date.getFullYear() 
        var  M = date.getMonth()+1
        var  D = date.getDate()
        var H = date.getHours() 
        var MIN = date.getMinutes()
        var s = date.getSeconds();

        Y = Y < 10 ? ('0' + Y) : Y
        M = M < 10 ? ('0' + M) : M
        H = H < 10 ? ('0' + H) : H
        MIN = MIN < 10 ? ('0' + MIN) : MIN
        s = s < 10 ? ('0' + s) : s
        D = D < 10 ? ('0' + D) : D
        var time = Y + '-' + M + '-' + D 
          return time
        },
        // 倒计时
         interval :function(faultDate,completeTime){
          var stime = Date.parse(new Date(faultDate));
          var etime = Date.parse(new Date(completeTime));
          var usedTime = etime - stime;  //两个时间戳相差的毫秒数
          var days=Math.floor(usedTime/(24*3600*1000));
          //计算出小时数
          var leave1=usedTime%(24*3600*1000);    //计算天数后剩余的毫秒数
          var hours=Math.floor(leave1/(3600*1000));
          //计算相差分钟数
          var leave2=leave1%(3600*1000);        //计算小时数后剩余的毫秒数
          var minutes=Math.floor(leave2/(60*1000));
          var time = days + "天"+hours+"时"+minutes+"分";
          return time;
        },
        formatDateTime6:function(str){
          var date = new Date(str * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() 
      var  M = date.getMonth()+1
      var  D = date.getDate()
      var H = date.getHours() 
      var MIN = date.getMinutes()
      var s = date.getSeconds();
  
      Y = Y < 10 ? ('0' + Y) : Y
      M = M < 10 ? ('0' + M) : M
      H = H < 10 ? ('0' + H) : H
      MIN = MIN < 10 ? ('0' + MIN) : MIN
      s = s < 10 ? ('0' + s) : s
      D = D < 10 ? ('0' + D) : D
      var time = Y + '-' + M + '-' + D +' ' + H+ ':' + MIN + ':' + s 
      return time
        },
    
    
  };